import java.io.*;
import java.util.Properties;

public class Helper {
    private static Properties properties;

    private static Properties getProperties() {
        if (properties == null) {
            properties = new Properties();
            File f = new File("GitExport.conf");
            System.out.println(f.getAbsolutePath());
            if (!f.exists()) {
                try {
                    f.createNewFile();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            try (InputStream stream = new FileInputStream(f);
                 InputStreamReader reader = new InputStreamReader(stream, "utf-8")) {
                properties.load(reader);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return properties;
    }

    private static void save() {
        getProperties();
        try (OutputStream stream = new FileOutputStream(new File("GitExport.conf"));
             OutputStreamWriter writer = new OutputStreamWriter(stream, "utf-8")) {
            properties.store(writer, null);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static String getValue(String key){
        return getProperties().getProperty(key);
    }

    public static void setValue(String key, String value){
        getProperties().setProperty(key, value);
        save();
    }

    public static String getSource() {
        return getProperties().getProperty("source");
    }

    private static void setSource(String value) {
        getProperties().setProperty("source", value);
        save();
    }

    public static String getProject() {
        return getProperties().getProperty("project");
    }

    private static void setProject(String value) {
        getProperties().setProperty("project", value);
        save();
    }

    public static String getOutput() {
        return getProperties().getProperty("output");
    }

    private static void setOutput(String value) {
        getProperties().setProperty("output", value);
        save();
    }
}
